package hu.jonas.junitmax;


import org.eclipse.jdt.junit.model.ITestCaseElement;
import org.eclipse.jdt.junit.model.ITestElement.Result;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

public class TestResultTableLabelProvider implements ITableLabelProvider {

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		if (element instanceof ITestCaseElement) {
			ITestCaseElement item = (ITestCaseElement) element;

			if (columnIndex == 0) {
				Result testResult = item.getTestResult(false);
				if (testResult == Result.OK) {
					return Activator.testOk;
				} else {
					return Activator.testFail;
				}
			}
		}
		
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		if (element instanceof ITestCaseElement) {
			ITestCaseElement item = (ITestCaseElement) element;

			switch (columnIndex) {
			case 0:
				return item.getTestClassName();
			case 1:
				return item.getTestMethodName();
			case 2:
				return String.format("%1$4.3f", item.getElapsedTimeInSeconds());
			}
		}
		
		return null;
	}

	@Override
	public void addListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isLabelProperty(Object element, String property) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub
		
	}

}
